<template>
    <div>
        这里是首页
<router-link to="/permission" v-if="isShowBtn">去权限页</router-link>
<button @click="logout()">退出</button>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "home",
  data() {
    return {
      isShowBtn: true
    };
  },
  beforeRouteEnter (to, from, next) {
      next(vm => {
          vm.isShowBtn = vm.checkPermission()
      })
  },
  computed: {
    ...mapGetters(["permission_routers"])
  },
  methods: {
    checkPermission() {
      let routers = this.permission_routers,
      len = routers.length;
      for (let i = 0; i < len; i++) {
          const router = routers[i];
          if (router.path === "/permission") {
          return true;
        }
      }
      return false;
    },
    logout() {
      this.$store.dispatch("LogOut").then(() => {
        location.reload();
      });
    }
  }
};
</script>

<style>
</style>
